﻿using AnChao.WPF.Controls.MDI.Core;
using CRootGUI.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnChao.WPF.Controls.MDI
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        

        public MainWindow()
        {
            InitializeComponent();

            
        }

        

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var control = sender as MenuItem;
                if (control != null)
                {
                    
                    TabItemDraggable tabItem = new TabItemDraggable();
                    tabItem.Header = control.Header;
                    tabItem.AllowDrop = true;

                    ContextMenu CurrentMenu = new ContextMenu();
                    MenuItem currentMenuItem = new MenuItem() { Header = "窗外窗" };
                    currentMenuItem.Click += tabItem.SingleWindow;
                    CurrentMenu.Items.Add(currentMenuItem);


                    tabItem.ContextMenu = CurrentMenu;
                    if (control.Name.Contains("1"))
                    {
                        UserControl1 con = new UserControl1();
                        tabItem.Content = con;
                        GroupWindow.Instance.AddControl(con);
                    }
                    else
                    {
                        UserControl2 con = new UserControl2();
                        tabItem.Content = con;
                        GroupWindow.Instance.AddControl(con);
                    }

                    switch (control.Name)
                    {
                        case "top_1":
                        case "top_2":
                            tab_top.Items.Add(tabItem);
                            tab_top.SelectedIndex = tab_top.Items.Count - 1;
                            break;
                        
                        case "down_1":
                        case "down_2":
                            tab_down.Items.Add(tabItem);
                            tab_down.SelectedIndex = tab_top.Items.Count - 1;
                            break;
                        default:
                            break;
                    }
                }


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

      
        
    }
}
